<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>访问信息列表</title>
    <spring:url value="/resources/jquery-easyui-1.5.3/themes/default/easyui.css"
                var="easyuiCss"/>
    <link href="${easyuiCss}" rel="stylesheet"/>

    <spring:url value="/resources/jquery-easyui-1.5.3/themes/icon.css"
                var="easyuiIcon"/>
    <link href="${easyuiIcon}" rel="stylesheet"/>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/jquery.min.js" />"></script>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/jquery.easyui.min.js" />"></script>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js" />"></script>
    <script type="text/javascript">
        function showVisit() {
            $("#functionList").show();
            $("#labelName").show();
        }
    </script>
    <style>
        input checkbox {
            white-space: nowrap;
            font-size: 1.5em;
            zoom: 160%;
        }

        span {

            font-size: 18px;
            margin-left: 1.5%;
        }

        th {
            white-space: nowrap;
            align: center;
            text-align: center;
            margin: 0px auto;
        }
    </style>

</head>
<body>
<table id="dg" class="easyui-datagrid" title="访问信息列表" style="height:500px" data-options="
            fit:true,
            rownumbers:true,
            autoRowHeight:true,
            pagination:true,
            SingleSelect:false,
            pageSize:20,
            pageList: [20, 30, 50],
            url:'/visit/list',
            method:'get',
            toolbar:'#tb'">
    <thead>
    <tr>
        <th field="cb" checkbox="true"></th>
        <th field="customername">到访客户姓名</th>
        <th field="receptionpeople">接待人员姓名</th>
        <th field="receptiondepartment">接待人员部门</th>
        <th field="ordertime">预约访问时间</th>
        <th field="factarrivetime">实际访问时间</th>
        <th field="factleavetime">实际离开时间</th>
        <th field="dateentrytime">数据录入时间</th>
        <th field="doorpostname">当值门岗姓名</th>
        <th field="state">到访状态</th>
        <th field="remarks">备注</th>

    </tr>
    </thead>
</table>
<div id="tb">
    <div>
        <a href="javascript:openVisitAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
        <a href="javascript:openVisitModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit"
           plain="true">修改</a>
        <%--<a href="javascript:deleteVisit()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>--%>
    </div>
    <div>
        &nbsp;到访客户姓名:<input type="text" id="customernameSearch" name="customername" style="width: 100px"
                            onkeydown="if(event.keyCode==13) searchVisit()"/>
        &nbsp;接待人员姓名:<input type="text" id="receptionpeopleSearch" name="receptionpeople" style="width: 100px"
                            onkeydown="if(event.keyCode==13) searchVisit()"/>
        &nbsp;接待人员部门:<input type="text" id="receptiondepartmentSearch" name="receptiondepartment" style="width: 100px"
                            onkeydown="if(event.keyCode==13) searchVisit()"/>
        &nbsp;当值门岗姓名:<input type="text" id="doorpostnameSearch" name="doorpostname" style="width: 100px"
                            onkeydown="if(event.keyCode==13) searchVisit()"/>
        <a href="javascript:resetValue()" class="easyui-linkbutton" iconCls="icon-search" plain="true">清空</a>
        <a href="javascript:searchVisit()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>

<div id="dlg" class="easyui-dialog" style="padding: 10px 20px;width: 460px;height: 420px;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <div style="float: left" hidden="hidden">
            <div style="float: left;font-size: 20px;width: 278px;"><span>id:<input type="text" name="id"
                                                                                   id="id"/></span></div>
        </div>
        <div style="float: left">
            <div style="float: left;font-size: 20px;width: 278px;"><span>到访客户姓名:<input type="text" name="customername"
                                                                                       id="customername"/></span></div>
        </div>
        <div>
            <div style="float: left;font-size: 20px;width: 278px;"><span>接待人员姓名:<input type="text"
                                                                                       name="receptionpeople"
                                                                                       id="receptionpeople"/></span>
            </div>
        </div>
        <div style="float: left">
            <div style="float: left;font-size: 20px;width: 278px;"><span>接待人员部门:<input type="text"
                                                                                       name="receptiondepartment"
                                                                                       id="receptiondepartment"/></span>
            </div>
        </div>
        <div>
            <div style="float: left;font-size: 20px;width: 278px;"><span>当值门岗姓名:<input type="text" name="doorpostname"
                                                                                       id="doorpostname"/></span>
            </div>
        </div>
        <div>
            <div style="float: left;font-size: 20px;width: 278px;"><span>预约访问时间:<input type="text" name="ordertime"
                                                                                       class="easyui-datetimebox"
                                                                                       id="ordertime"/></span>
            </div>
        </div>
        <div style="float: left">
            <div style="float: left;font-size: 20px;width: 278px;"><span>实际访问时间:<input type="text" name="factarrivetime"
                                                                                       class="easyui-datetimebox"
                                                                                       id="factarrivetime"/></span>
            </div>
        </div>
        <div>
            <div style="float: left;font-size: 20px;width: 278px;"><span>实际离开时间:<input type="text" name="factleavetime"
                                                                                       class="easyui-datetimebox"
                                                                                       id="factleavetime"/></span>
            </div>
        </div>
         <div style="float: left" hidden="hidden">
             <div style="float: left;font-size: 20px;width: 278px;"><span>数据录入时间:<input type="text" name="dateentrytime"
                                                                                        class="easyui-datetimebox"
                                                                                        id="dateentrytime"/></span></div>
         </div>

        <div style="float: left">
            <div style="float: left;font-size: 20px;width: 278px;"><span>客户访问状态:
                <select class="easyui-combobox" id="state" name="state" style="width: 154px;" editable="false" panelHeight="auto">
	 						<option value="">请选择客户到访状态</option>
	 						<option value="待访">待访</option>
	 						<option value="取消">取消</option>
	 						<option value="过期未访">过期未访</option>
	 						<option value="门岗已放行">门岗已放行</option>
	 						<option value="访问中">访问中</option>
	 						<option value="离开">离开</option>
	 					</select>
                </span>
            </div>
        </div>
        <div style="float: left">
            <div style="float: left;font-size: 20px;width: 420px;"><span>信息备注:<textarea
                    rows="1"
                    cols="36" name="remarks"
                    id="remarks"></textarea></span>
            </div>
        </div>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveVisit()" class="easyui-linkbutton" iconCls="icon-ok" id="saveBtn">保存</a>
    <a href="javascript:closeVisitDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
<script type="text/javascript">


    var url;
    var id;

    //清空搜索框的值
    function resetValue() {
        $("#customernameSearch").val("");//到访客户姓名
        $("#receptionpeopleSearch").val("");//到访客户姓名
        $("#receptiondepartmentSearch").val("");//到访客户姓名
        $("#doorpostnameSearch").val("");//到访客户姓名
    }

    //展现信息添加框
    function openVisitAddDialog() {
        $("#dlg").dialog("open").dialog("setTitle", "添加访问记录信息");
        resetValue();
        //url = '/visit/save';
    }

    //清空文本框的值
    function resetValue() {
        $("#fm .easyui-datetimebox").datetimebox({ readonly: false });
        $("#customername").val("").attr("readonly",false);//到访客户姓名
        $("#receptionpeople").val("").attr("readonly",false);//接待人员姓名
        $("#receptiondepartment").val("").attr("readonly",false);//接待人员部门
        $("#ordertime").datebox("setValue", "");//预约到访时间
        $("#factarrivetime").datebox("setValue", "");//实际到访时间
        $("#factleavetime").datebox("setValue", "");//实际离开时间
        $("#dateentrytime").datebox("setValue", "");//数据录入时间
        $("#doorpostname").val("").attr("readonly",false);//当值门岗姓名
        $("#state").combobox("setValue","请选择客户到访状态");
        $("#remarks").val("").attr("readonly",false);//备注
        // $("#toTime").datebox("setValue","");

    }

    //保存访问信息记录
    function saveVisit() {
        var orderTime = $("#ordertime").datebox('getValue')//预约访问时间
        var factarrivetime = $("#factarrivetime").datebox('getValue')//实际访问时间
        var factleavetime = $("#factleavetime").datebox('getValue')//实际离开时间
        //var start=new Date(a1.replace("-", "/").replace("-", "/"));
        var order = new Date(orderTime.replace("-", "/").replace("-", "/"));
        var arrive = new Date(factarrivetime.replace("-", "/").replace("-", "/"));
        var leave = new Date(factleavetime.replace("-", "/").replace("-", "/"));
       // alert("===order===" + order + "===arrive===" + arrive + "===leave===" + leave)
       // alert("===url==="+url)
        $("#fm").form("submit", {
            url: '/visit/save',
            onSubmit: function () {
                if ($("#customername").val().trim() == "") {
                    $.messager.alert("系统提示", "客户名称不能为空！！！");
                    return false;
                }
                if ($("#receptionpeople").val().trim() == "") {
                    $.messager.alert("系统提示", "接待人员不能为空！！！");
                    return false;
                }
                if ($("#receptiondepartment").val().trim() == "") {
                    $.messager.alert("系统提示", "接待人员部门不能为空！！！");
                    return false;
                }
                //var v = $('#dd').datebox('getValue');
                if ($("#ordertime").datebox('getValue').trim() == "") {
                    $.messager.alert("系统提示", "预约到访时间不能为空！！！");
                    return false;
                }
                if ($("#factarrivetime").datebox('getValue').trim() == "") {
                    $.messager.alert("系统提示", "实际到访时间不能为空！！！");
                    return false;
                }
                if ($("#factleavetime").datebox('getValue').trim() == "") {
                    $.messager.alert("系统提示", "实际离开时间不能为空！！！");
                    return false;
                }
                if (order > arrive || arrive > leave) {
                    $.messager.alert("系统提示", "预约时间<实际到访时间<实际离开时间！！！");
                    return false;
                }
                /* if ($("#dateentrytime").datebox('getValue').trim() == "") {
                     $.messager.alert("系统提示", "数据录入时间不能为空！！！");
                     return false;
                 }*/
                if ($("#doorpostname").val().trim() == "") {
                    $.messager.alert("系统提示", "当值门岗姓名不能为空！！！");
                    return false;
                }

                if ($("#state").val().trim() == "") {
                    $.messager.alert("系统提示", "到访状态不能为空！！！");
                    return false;
                }
                return $(this).form("validate");
            },
            success: function (result) {
                var result = eval('(' + result + ')');
                if (result.success) {
                    $.messager.alert("系统提示", result.message);
                    resetValue();
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                } else {
                    $.messager.alert("系统提示", result.message);
                    return;
                }
            }
        });
    }

    function openVisitModifyDialog() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        resetValue()
        var row = selectedRows[0];
        $("#dlg").dialog("open").dialog("setTitle", "编辑访问记录信息");
        $("#customername").val(row.customername).attr("readonly",true);
        $("#receptionpeople").val(row.receptionpeople).attr("readonly",true);
        $("#receptiondepartment").val(row.receptiondepartment).attr("readonly",true);
        $("#fm .easyui-datetimebox").datetimebox({ readonly: true });
        $("#ordertime").datetimebox("setValue",row.ordertime).attr("readonly",true);
        $("#factarrivetime").datetimebox("setValue",row.factarrivetime);
        $("#factleavetime").datetimebox("setValue",row.factleavetime);
        $("#dateentrytime").datetimebox("setValue",row.dateentrytime);
        $("#doorpostname").val(row.doorpostname).attr("readonly",true);
        $("#remarks").val(row.remarks).attr("readonly",true);
        $("#id").val(row.id);
        $("#state").combobox("setValue",row.state);
        //url = "/visit/update?id=" + row.id;
    }

    function searchVisit() {
        $("#dg").datagrid('load', {
            "customername": $("#customernameSearch").val(),
            "receptionpeople": $("#receptionpeopleSearch").val(),
            "receptiondepartment": $("#receptiondepartmentSearch").val(),
            "doorpostname": $("#doorpostnameSearch").val()
        });
    }

    function closeVisitDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }

</script>
</body>

